package com.chat.comment.exception;

import com.chat.comment.core.ResponseResult;
import com.comment.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 自定义异常处理
 * @author: DT
 * @date: 2021/4/19 21:17
 * @version: v1.0
 */
@ControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResponseResult<?> exceptionHandler(Exception e) {
        log.error("服务器异常", e);
        return ResponseResult.error(e.getMessage());
    }

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public ResponseResult<?> serviceException(ServiceException e) {
        log.error("服务异常", e);
        return ResponseResult.error(e.getMessage());
    }
}
